package com.hnchances.controller;

import com.hnchances.service.CodeService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Description: 验证码接口
 */
@RestController
public class CodeController {

    @Autowired
    private CodeService codeService;
    /**
     * 给当前手机发送一条验证码
     * @param phone 手机号
     * @return 发送结果
     * @throws Exception
     */
    @ApiOperation("验证码发送接口")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="String",name = "phone",value = "手机号",required = true)
    })
    @PostMapping("/sendCode")
    public String sendCode(@RequestParam String phone) {
        return codeService.sendCode(phone);
    }
    /**
     * 根据电话号码获取缓存中的验证码
     * @param phone
     * @return
     */
    @ApiOperation("获取验证码接口")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="String",name = "phone",value = "手机号",required = true)
    })
    @PostMapping("/getCode")
    public String getCode(@RequestParam String phone) {
        return codeService.getCode(phone);
    }
}

